/*
    libhdvbd - Library for building sophisticated DVB applications
    Copyright (C) 2012 Tony Houghton <h@realh.co.uk>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "dvbenc.h"
#include "freesat-decode.h"
#include "huffman.h"
#include "i18n.h"

char *
hdvb_freesat_str_to_utf8(const guint8 *s, int l)
{
    if (!s || !l)
    {
        g_warning(_("NULL string in Freesat EPG"));
        return NULL;
    }
    if (s[0] == 0x1f)
    {
        if (s[1] == 1)
        {
            return hdvb_huffman_decode(s + 2, l - 2,
                    hdvb_freesat_huffman_table1);
        }
        else if (s[1] == 2)
        {
            return hdvb_huffman_decode(s + 2, l - 2,
                    hdvb_freesat_huffman_table2);
        }
        else
        {
            g_warning(_("String looks like Freesat Huffman encoding but with "
                    "unknown table"));
            return NULL;
        }
    }
    return hdvb_dvb_str_to_utf8(s, l);
}
